﻿#pragma once
#ifndef Mutex_hpp
#define Mutex_hpp

#include<mutex>
#include<atomic>
#include"./MutexInterface.hpp"

namespace MMF{

    class Mutex: public MutexInterface
    {
        std::atomic<bool> mLocked = false;

    public:

        bool Locked()
        {
            return mLocked;
        }
        
        void Lock()
        {
            while(mLocked.load());
            mLocked = true;
        }
        
        void Unlock()
        {
            mLocked = false;
            mLocked.notify_all();
        }

        bool TryLock()
        {
            bool old = false;
            return mLocked.compare_exchange_strong(old, true, std::memory_order_acquire);
        }
    };
}


#endif